package com.jiejie.controller;


import com.jiejie.commons.ServerResponse;
import com.jiejie.entity.Comments;
import com.jiejie.entity.LoginCustomer;
import com.jiejie.entity.Movie;
import com.jiejie.entity.Schedule;
import com.jiejie.service.ICommentsService;
import com.jiejie.service.IMovieService;
import com.jiejie.service.IScheduleService;
import com.jiejie.util.TokenUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 辰广
 * @since 2022-10-05
 */
@RestController
public class ScheduleController {

    @Resource
    private IMovieService movieService;
    @Resource
    private IScheduleService scheduleService;
    @Resource
    private ICommentsService commentsService;

    @GetMapping("movieSchedule")
    public ModelAndView getMovieSchedule(@RequestParam("movieId")Integer movieId){
        System.out.println("movieId:"+movieId);
        Movie movie=movieService.getMovieDetailById(movieId);
        LocalDate scheduleDate=LocalDate.now();
        List<Schedule> scheduleList=scheduleService.getScheduleByMovieId(movieId,scheduleDate);
        float allCommentsScore=commentsService.getAllCommentsScore(movieId);
        String[] strType=movie.getMovieType().split(" ");
        List<String> listType = new ArrayList<>(Arrays.asList(strType));
        System.out.println(listType);

        String dataOne=LocalDate.now().getMonthValue()+"月"+LocalDate.now().getDayOfMonth()+"日";
        String dataTwo=LocalDate.now().getMonthValue()+"月"+(LocalDate.now().getDayOfMonth()+1)+"日";
        System.out.println("dataOne:"+dataOne+",dataTwo:"+dataTwo);

        ModelAndView mav=new ModelAndView();
        //电影表
        mav.addObject("movie",movie);
        //总评分
        mav.addObject("allCommentsScore",allCommentsScore);
        //电影类型
        mav.addObject("listType",listType);
        //排片表
        mav.addObject("scheduleList",scheduleList);
        mav.addObject("dataOne",dataOne);
        mav.addObject("dataTwo",dataTwo);
        //演员表



        mav.setViewName("pages/cinema_movies");
        return mav;
    }


}





